﻿using MvvmCross.Plugins.Messenger;
using Sidvall.Serialization;
using Sidvall.UI.ViewModels;

namespace Sidvall.UI.Messaging
{
    public class ViewModelMessage : MvxMessage
    {
        #region Public Members

        public string Key { get; set; }
        public string Value { get; set; }
        public string Context { get; set; }

        #region Create

        public static ViewModelMessage Create(object sender, string key, string value, string context)
        {
            return new ViewModelMessage(sender)
            {
                Key = key,
                Value = value,
                Context = context,
            };
        }

        #endregion
        #region CreateIsBusyMessage

        public static ViewModelMessage CreateIsBusyMessage(object sender, bool isBusy, string message, string scope)
        {
            return new ViewModelMessage(sender)
            {
                Key = ViewModelEventTypes.IsBusyChanged,
                Value = Sidvall.Serialization.SerializerManager.Current.Serialize(isBusy),
                Context = BusyContext.Serialize(message, scope),
            };
        }

        #endregion
        #region IsBusyMessage

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Sidvall.Serialization.StringExtension.Equals(System.String,System.String,System.Boolean,System.StringComparison)")]
        public static bool IsBusyMessage(ViewModelMessage message)
        {
            return (message?.Key).Equals(ViewModelEventTypes.IsBusyChanged, true, System.StringComparison.OrdinalIgnoreCase);

        }

        #endregion

        #endregion
        #region Constructors

        public ViewModelMessage(object sender)
            : base(sender)
        {
        }

        #endregion
    }
}
